<template>
	<view class="coupon-block">
		<template v-if="lst.length>0">
			<block v-for='(item,index) in lst' :key="index">
				<item :itemData='item' :itemType='1' @itemClick='itemClick'></item>
			</block>
		</template>
		<template v-if="lst.length==0">
			<view class="no-emty" style="font-size: 26rpx;color: #999;">暂无可用优惠券</view>
		</template>
	</view>
</template>

<script>
	import item from '@/pages/coupon/components/item.vue'
	export default {
		components: {
			item
		},
		onLoad(e) {
			// console.log('e', e)
			if(e){
				this.ids=e.ids
				this.init()
			}
		},
		data() {
			return {
				lst: [],
				ids:'',
			}
		},
		methods: {
			init() {
				this.$http('coupon.getUsableCoupon', {
					token: this.$tools.getToken(),
					commodity_ids:this.ids
				}).then(res => {
					console.log('res', res)
					 if(res.code==200){
						 this.lst=res.data.list
					 } 
				})
			},
			itemClick(item) {
				uni.setStorageSync('couponObj',{
					 coupon_id:item.id,
					 counponName:item.coupon_name,
					 counponPrice:item.coupon_price/100
				})
				uni.navigateBack()
				 console.log('item',item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.coupon-block {

		padding: 0 32rpx;
	}

	.no-emty {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 30rpx;
	}
</style>
